package com.example.bootdemo.listeners;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;


public class MyAppStartListener implements ApplicationListener<ApplicationStartedEvent> {

    private static Logger logger = LoggerFactory.getLogger(MyAppStartListener.class);

    @Override
    public void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) {

        logger.info("监听到ApplicationStartedEvent事件......");

        String className = applicationStartedEvent.getSource().getClass().getName();

        logger.info("className={}",className);

        ConfigurableApplicationContext applicationContext = applicationStartedEvent.getApplicationContext();

        Object bean = applicationContext.getBean("userSpecificationRepository");

        String beanClassName = bean.getClass().getName();

        logger.info("beanClassName={}",beanClassName);

    }
}
